package com.cold.demo.security.service;

import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service
public class MyUserDetailsService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (!"user1".equals(username)) {
            throw new UsernameNotFoundException("用户名不存在：" + username);
        }
        return new User("user1", "user1", Collections.singletonList(new SimpleGrantedAuthority("ADMIN")));
    }

}
